package com.cc.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.cc.constant.BusinessStatusConstant.*;

/**
 * @author CHENCHEN
 * @company 北京学佳澳教育科技
 * @create 2023-03-02 14:56
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class CommonResponse<T> {

    private Integer code;

    private String msg;

    private T data;

    public CommonResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    //成功，无返回值
    public static CommonResponse SUCCESS = new CommonResponse(OK, OK_MESSAGE);

    //成功，有返回值
    public static CommonResponse SUCCESS(Object data){
        return new CommonResponse(OK, OK_MESSAGE, data);
    }

    //失败，无返回回执
    public static CommonResponse FAIL = new CommonResponse(ERR, ERR_MESSAGE);

    //业务异常，程序出错
    public static CommonResponse BUSINESS_FAIL = new CommonResponse(BUSINESS_EXCEPTION, BUSINESS_EXCEPTION_MESSAGE);

    ////业务异常，程序出错
    public static CommonResponse BUSINESS_FAIL(Integer code, String msg){
        return new CommonResponse(code, msg);
    }

    ////业务异常，程序出错
    public static CommonResponse BUSINESS_FAIL(Integer code, String msg, Object data){
        return new CommonResponse(code, msg, data);
    }
}
